package com.wypiwyl.footastic;

import android.graphics.Point;

public class Player {

    // cle du joueur
    private PlayerKey playerKey;

    // declaration de la position du joueur 
    private Point position;
    // direction du joueur
//    private Direction direction;
    private int direction;
    
    // declaration du rayon d'interception
    private int rayonInterception = 50;
    // declaration de l'angle d'interception
    private int angleInterception = 90;
    // declaration du rayon de la passe (pour un niveau)
    private int distancePasse = 200;
    // declaration de l'angle de passe
    private int anglePasse = 90;
    
    // agit sur les possibilites du chemin
    private int distanceMax = 200;
    private int dexteriteBalleAuPied = 30;
    
    
    /** attributs lors d'un tour de jeu **/
    // declarationde l'indicateur pour savoir le joueur a deja perdu le ballon lors du tour
    private boolean ballLost = false;


    private int speed = 200;

    public Player(boolean _bTeam1, int _numPlayer, Direction _direction, Point _position) {
        this.playerKey = new PlayerKey(_bTeam1, _numPlayer);
//        this.direction = _direction;
        this.position = _position;
        
        if (_bTeam1) {
            this.direction = 0;
        } else {
            this.direction = 180;
        }
    }

    
    public void initRound() {
        //
        ballLost = false;
    }

    public boolean isbTeamA() {
        return getPlayerKey().isbTeamA();
    }

    public int getNumPlayer() {
        return getPlayerKey().getNumPlayer();
    }

    public PlayerKey getPlayerKey() {
        return playerKey;
    }

    public void setPlayerKey(PlayerKey playerKey) {
        this.playerKey = playerKey;
    }

//    public Direction getDirection() {
//        return direction;
//    }
//
//    public void setDirection(Direction direction) {
//        this.direction = direction;
//    }
//
//    public int getValueDirection() {
//        return direction.getValue();
//    }

    public Point getPosition() {
        return position;
    }

    public void setPosition(Point nPosition) {
        position = nPosition;
    }
    
    public int getSpeed() {
        return speed;
    }

    public int getDiagonalDistance() {
        return (int) (speed / Math.sqrt(2));
    }

    public int getDistancePasse() {
        return distancePasse;
    }

    public int getAnglePasse() {
        return anglePasse;
    }

    public int getDeltaDistance(Point p) {
        double X = Math.pow(p.x - this.position.x, 2);
        double Y = Math.pow(p.y - this.position.y, 2);
        return (int) Math.sqrt(X + Y);
    }

    public int getRayonInterception() {
        return rayonInterception;
    }

    public int getAngleInterception() {
        return angleInterception;
    }
    
    

    public boolean isBallLost() {
        return ballLost;
    }


    public void setBallLost(boolean ballLost) {
        this.ballLost = ballLost;
    }


//    public Point getPositionRotationH() {
//        //
//        int xH = 0;
//        int yH = 0;
//
//        switch (getDirection()) {
//            case NORTH:
//                xH = getPosition().x + speed;
//                yH = getPosition().y - speed;
//            break;
//            case NORTH_EAST:
//                xH = getPosition().x + speed;
//                yH = getPosition().y;
//            break;
//            case EAST:
//                xH = getPosition().x + speed;
//                yH = getPosition().y + speed;
//            break;
//            case SOUTH_EAST:
//                xH = getPosition().x;
//                yH = getPosition().y + speed;
//            break;
//            case SOUTH:
//                xH = getPosition().x - speed;
//                yH = getPosition().y + speed;
//            break;
//            case SOUTH_WEST:
//                xH = getPosition().x - speed;
//                yH = getPosition().y;
//            break;
//            case WEST:
//                xH = getPosition().x - speed;
//                yH = getPosition().y - speed;
//            break;
//            case NORTH_WEST:
//                xH = getPosition().x;
//                yH = getPosition().y - speed;
//            break;
//        }
//
//        return new Point(xH, yH);
//    }

//    public Point getPositionRotationAH() {
//        //
//        int xH = 0;
//        int yH = 0;
//
//        switch (getDirection()) {
//            case NORTH:
//                xH = getPosition().x - speed;
//                yH = getPosition().y - speed;
//            break;
//            case NORTH_EAST:
//                xH = getPosition().x;
//                yH = getPosition().y - speed;
//            break;
//            case EAST:
//                xH = getPosition().x + speed;
//                yH = getPosition().y - speed;
//            break;
//            case SOUTH_EAST:
//                xH = getPosition().x + speed;
//                yH = getPosition().y;
//            break;
//            case SOUTH:
//                xH = getPosition().x + speed;
//                yH = getPosition().y + speed;
//            break;
//            case SOUTH_WEST:
//                xH = getPosition().x;
//                yH = getPosition().y + speed;
//            break;
//            case WEST:
//                xH = getPosition().x - speed;
//                yH = getPosition().y + speed;
//            break;
//            case NORTH_WEST:
//                xH = getPosition().x - speed;
//                yH = getPosition().y;
//            break;
//        }
//
//        return new Point(xH, yH);
//    }


    public int getDistanceMax() {
        return distanceMax;
    }


    public int getDexteriteBalleAuPied() {
        return dexteriteBalleAuPied;
    }


    public int getDirection() {
        return direction;
    }


    public void setDirection(int direction) {
        this.direction = direction;
    }
    
    public boolean isPlayerOwnerBall() {
        return Arena.getInstance().isOwnerBall() && Arena.getInstance().getOwnerBall().equals(playerKey);
    }
    
}
